jQuery().ready(function() {
	var url = jQuery('link[rel=person_suggest]').attr('href');
	jQuery("[name=_authors]").autocomplete(url, {
	    'minChars': 2, // how many characters should be typed 
	                   // to ask server for suggestion

	    'formatItem': function (row, i, num) {
		return ""+row.fullname+" ("+row.oid+")";
	    },

	    'fillInput': function (v, $input) {
		var t = $input.val();
		var p = t.lastIndexOf(',');
		if (p == -1) $input.val(v);
		else $input.val(jQuery.trim(t.substr(0, p)) + ", " + v);
	    },

	    'parseInput': function (q) {
		var a = q.split(',');
		var item = a[a.length - 1];
		item = jQuery.trim(item);
		return item;
	    }
	});
});
